package com.future.account.config;

import com.netflix.client.config.IClientConfig;
import com.netflix.loadbalancer.AbstractLoadBalancerRule;
import com.netflix.loadbalancer.Server;

import java.util.List;

/**
 * 自定义负载均衡策略
 *
 * @author shiyong
 * 2021/6/10 8:16
 */
public class MyRule extends AbstractLoadBalancerRule {

    /**
     * Concrete implementation should implement this method so that the configuration set via
     * {@link IClientConfig} (which in turn were set via Archaius properties) will be taken into consideration
     *
     * @param clientConfig 客户端配置
     */
    @Override
    public void initWithNiwsConfig(IClientConfig clientConfig) {

    }

    @Override
    public Server choose(Object key) {
        System.out.println("自定义负载均衡策略");
        List<Server> allServers = getLoadBalancer().getAllServers();

        return allServers.get(0);
    }


}
